package com.qf.controller;/*
 *保护你的大熊
 *2021/11/18
 *21:13
 */

import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
  
    @Autowired
    private UserService userService;

    @RequestMapping("/list")
    public String list(Model model){
        List<User> list = userService.findUserAll();
        model.addAttribute("users", list);
        return "user";
    }

    @RequestMapping("/list2")
    public String list2(Model model){
        User user = new User();
        user.setUsername("张三");
        user.setPassword("123");
        user.setGender(true);
        user.setRegistTime(new Date());

        userService.insert(user);
        List<User> list = userService.findUserAll();
        model.addAttribute("users", list);
        return "user";
    }

    @RequestMapping("/list3")
    public String list3(Model model){
        userService.delete(6);
        model.addAttribute("users");
        List<User> list = userService.findUserAll();
        model.addAttribute("users", list);
        return "user";
    }

    @RequestMapping("/list4")
    public String list4(Model model){
        User user = new User();
        user.setId(7);
        user.setUsername("王猛");
        user.setPassword("234");
        user.setGender(false);
        user.setRegistTime(new Date());
        userService.update(user);
        List<User> list = userService.findUserAll();
        model.addAttribute("users", list);
        return "user";
    }
}
